package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingElderDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.entity.Page.NursingProjectPage;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> queryNusingProject(NursingProjectPage nursingProjectPage) {
        PageHelper.startPage(nursingProjectPage.getPage(),nursingProjectPage.getPageSize());
        Page<NursingProjectVo> page =nursingProjectMapper.queryNusingProject(nursingProjectPage);


        return PageResponse.of(page.getResult());
    }

    @Override
    public int insertNursingProject(NursingProjectDto nursingProject) {
        LocalDateTime now =LocalDateTime.now();
        if(nursingProject!=null){
            NursingProject nusre= BeanUtil.toBean(nursingProject,NursingProject.class);
//            nusre.setCreateTime(now);
//            nusre.setUpdateTime(now);
            nusre.setCreateBy(1L);
            nursingProjectMapper.insertNursingProject(nusre);
            return 1;
       }


        return 0;
    }

    @Override
    public NursingProjectVo queryNusingProjectById(Integer id) {
        NursingProject nursingProject=nursingProjectMapper.queryNusingProjectById(id);
        NursingProjectVo nursingProjectVo=BeanUtil.toBean(nursingProject,NursingProjectVo.class);
        return nursingProjectVo;
    }

    @Override
    public int updateNursingProject(NursingProjectDto nursingProject) {
        if(nursingProject!=null){
        NursingProject nursing=BeanUtil.toBean(nursingProject,NursingProject.class);
        nursing.setUpdateTime(LocalDateTime.now());
        nursing.setUpdateBy(1L);
        nursingProjectMapper.updateNursingProject(nursing);
        return 1;
        }
        return 0;
    }

}
